package com.tjh.hive_data_compare.util;

import com.tjh.hive_data_compare.StartGetTable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

public class JavaFileUtil {
    private static final Logger logger = LogManager.getLogger(JavaFileUtil.class);

    public static void writeInFile(String path, String content) throws IOException {
        File file = new File(path);
        if (!file.exists()) {
            System.out.println("文件不存在,创建文件");
            file.createNewFile();
        }

        Writer writer = null;
        StringBuilder outputString = new StringBuilder();
        try {
            outputString.append(content + "\r\n");
            writer = new FileWriter(file, true); // true表示追加
            writer.write(outputString.toString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                writer.close();
            } catch (IOException e2) {
                e2.printStackTrace();
            }
        }
    }
}
